namespace EyeSoft.Testing.IO
{
	using System.IO;
	using System.Text;

	using EyeSoft.IO;

	public class MemoryFileInfo
		: IFileInfo
	{
		private readonly byte[] buffer;

		public MemoryFileInfo(string fileName, int length)
		: this(fileName, new byte[length])
		{
		}

		public MemoryFileInfo(string fileName, byte[] buffer)
		{
			this.buffer = buffer;
			FileName = fileName;
			Length = buffer.Length;
			DirectoryName = Path.GetDirectoryName(fileName);
		}

		public string FileName
		{
			get; private set;
		}

		public long Length
		{
			get; private set;
		}

		public string DirectoryName { get; private set; }

		public Stream OpenRead()
		{
			return
				new MemoryStream(buffer);
		}

		public Stream OpenWrite()
		{
			return
				new MemoryStream(buffer);
		}

		public string ReadAllText()
		{
			return
				Encoding.ASCII.GetString(buffer);
		}
	}
}